<template>
  <div class="selfcenter">
    <header-bar ></header-bar>
    <div class="self-container">
      <div class="input-groups">
        <form action="" v-on:submit.prevent="onSubmit">
          <div class="email"><input type="text" placeholder="请输入手机号" v-model="phoneNum" ></div>
          <div class="password">
            <input type="password" placeholder="请输入短信验证码" v-model="verifyCode" class="">
            <div class="verifyCodeBtn" :class="countdown>0 ? 'countdown':''" @click="getVerifyCode">{{countdown > 0 ? countdown + 's': '获取验证码'}}</div>
          </div>
          <div class="password"><input type="password" placeholder="请输入密码" v-model="password" class=""></div>
          <div class="submit"><input type="submit" value="注册" :class="{disabled:isDisabled}" :disabled='isDisabled'></div>
          <div @click="agree">
            <div class="check-box" :class="provicy? 'agree':''" ></div>我同意<a href="">《服务条款》</a>和<a href="">《隐私政策》</a>
          </div>
        </form>
        <div class="toLogin" @click="goToLogin">返回登录></div>
      </div>
    </div>
    <router-view ></router-view>
    <v-footer class="footer"></v-footer>
  </div>

</template>
<script>
import { mapGetters } from 'vuex'
import Footer from '@/components/public/Footer'
import topBar from '@/components/public/HeaderBar'
import showInfo from './showInfo'
import regex from '@/util/regex'
import { Toast } from 'mint-ui'

export default {
  name: 'register',
  data () {
    return {
      phoneNum: 13212341234,
      verifyCode: '',
      password: '',
      countdown: 0,
      provicy: true
    }
  },
  components: {
    'v-footer': Footer,
    'header-bar': topBar,
    'show-info': showInfo
  },
  methods: {
    getVerifyCode () {
      console.log('ok')
      if (!regex.isPhone(this.phoneNum)) {
        Toast('手机号码格式不正确')
        return
      }
      let that = this
      if (this.countdown > 0) {
        return
      }
      this.countdown = 3
      let timer = setInterval(function () {
        that.countdown = that.countdown - 1
        if (that.countdown <= 0) {
          clearInterval(timer)
        }
      }, 1000)
    },
    onSubmit () {
      console.log('表单提交了')
      // console.log(this.$store)
      this.$store.dispatch('setUserInfo', {mobile: this.phoneNum, password: this.password, smsVerifyCode: this.verifyCode, loginStatus: true})
    },
    goToLogin () {
      this.$router.push({path: '/self'})
    },
    agree () {
      this.provicy = !this.provicy
    }
  },
  computed: {
    isDisabled: function () {
      return this.phoneNum.length <= 0 || this.password.length <= 0
    }
  },
  localUserInfo: mapGetters(['localUserInfo'])
}
</script>
<style scoped>

.self-container{
  padding: 0 0.555556rem;
  background-color: #fff;
  margin-top: 3rem;
  height: calc(100vh - 1.17333rem - 1.30667rem - 3rem);
}

.input-groups input{
  width: 100%;
    height: 0.6rem;
    font-size: 0.4rem;
    line-height: 0.6rem;
    margin: 0.3rem 0;
    padding-left: 0;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: normal;
    font-weight: normal;
  background-color: #fff;
  height: 1.28rem;
}
.email::after, .password::after{
  position: absolute;
  left: -50%;
  bottom: 0;
  content: '';
    width: 200%;
    height: 1px;
    background: #d9d9d9;
    transform: scale(0.5);
    display: block;
}

.email, .password{
  background-color: #fff;
  position: relative;
}
.input-groups input[type="submit"]{
  margin: 0.5rem 0 0.3rem;
  height: 1.28rem;
  display: block;
    width: 100%;
    cursor: pointer;
    text-align: center;
    background-color: #b4282d;
    color: #fff;
    border-radius: 3px;
}
input[type="submit"].disabled{
  background-color: #cb7a7a;
}

.input-groups>p{
  text-align: center;
}

.verifyCodeBtn{
  width: 2.2rem;
  height: 0.7rem;
  padding: 0.1rem 0.2rem;
  text-align: center;
  border: 1px solid #666;
  display: inline-block;
  border-radius: 0.1rem;
  position: absolute;
  right: 0;
  bottom: 0.3rem;
}

.countdown{
  border: 1px solid #ccc;
  color: #ccc;
  pointer-events: none;

}

.input-groups .toLogin{
  display: table;
  font-size: 0.32rem;
  margin: 0 auto;
  margin-top: 0.6rem;
}

.check-box{
  width: 0.38rem;
  height: 0.38rem;
  border: 1px solid #999;
  border-radius: 0.1rem;
  margin:0.05rem 0.15rem 0 0;
  float: left;
}
  .agree{
    background-image: url("/static/images/select.png");
    background-size: 90% 90%;
    background-position: center;
  }
</style>
